
$(document).ready(function(){
  $(".risultatiItem:odd").addClass('dispari');
  $(".risultatiItem:even").addClass('pari');
        
  $(".risultatiItem").click(function(){
    $(this).parents("form:first").next().submit();
  });
});


$(document).ready(function(){
  if(!$("#sinistra .pages").hasClass("pages")) return;
  $("#sinistra > div:first").cycle({
    timeout: 0
  });
  var nr = $(".pages>div").length;
  $("#pagination-backend-cuspo").paginate({
    count: nr,
    start: 1,
    text_color: "#fff",
    display:2,
    onChange: function(numr){
      $("#sinistra > div:first").cycle({
        startingSlide: numr-1,
        timeout:0
      });
    }
    
  });
  $(".jPag-control-front a,.jPag-control-back a").css({
    "visibility":"hidden"
  });
  var page_selected = $("#sinistra td.selected").parents("div:first");
  $("#sinistra > div:first div").each(function(index){
    if($(this).attr("id") == $(page_selected).attr("id") )
      $($(".jPag-pages li")[index]).trigger("click");
  });
});

function getBaseURL() {
  var url = location.href;  // entire url including querystring - also: window.location.href;
  var baseURL = url.substring(0, url.indexOf('/', 14));


  if (baseURL.indexOf('http://localhost') != -1) {
    // Base Url for localhost
    var url = location.href;  // window.location.href;
    var pathname = location.pathname;  // window.location.pathname;
    var index1 = url.indexOf(pathname);
    var index2 = url.indexOf("/", index1 + 1);
    var baseLocalUrl = url.substr(0, index2);

    return baseLocalUrl + "/";
  }
  else {
    // Root Url for domain name
    return baseURL + "/";
  }

}

//gestisce la massima lunghezza delle textarea
$(document).ready(function() {  
    $('textarea[maxlength]').keyup(function(){  
        //get the limit from maxlength attribute  
        var limit = parseInt($(this).attr('maxlength'));  
        
        //get the current text inside the textarea  
        var text = $(this).val();  
        //count the number of characters in the text  
        var chars = text.length;  
        //check if there are more characters then allowed  
        if(chars > limit){  
            //and if there are use substr to get the text before the limit  
            var new_text = text.substr(0, limit);  
  
            //and change the current text with the new text  
            $(this).val(new_text);  
        }  
        $(".caratteri-rimanenti span").text(limit-chars)
    });  
  
});  


//resetta il tinymce
$(document).ready(function(){
  return;
  $(".switch-tmce").trigger("click");
})